package net.tp.algo.hash;

/**
 *
 * @author Trung Phan
 */
public class HashFunction {


    public static int java(String text) {
        int hash = 0;
        for (int i = 0; i < text.length(); i++) {
            char c = text.charAt(i);
            hash = hash * 31 + c;
        }
        return hash;
    }

    public static int rs(String text) {
        int a = 31;
        int b = 31;
        int hash = 0;
        for (int i = 0; i < text.length(); i++) {
            hash = hash * a + text.charAt(i);
            a = a * b;
        }
        return hash;
    }

}
